-
Notifications
You must be signed in to change notification settings - Fork 471
Use sizeof more pervasively #242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
CC: @MadCoder |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can't use that compiler specific sizeof pointer
src/queue_internal.h
Outdated
#endif | ||
#define _DISPATCH_CONTINUATION_PTRS 8 | ||
#if DISPATCH_HW_CONFIG_UP | ||
// UP devices don't contend on continuations so we don't need to force them to | ||
// occupy a whole cacheline (which is intended to avoid contention) | ||
#define DISPATCH_CONTINUATION_SIZE \ | ||
(_DISPATCH_CONTINUATION_PTRS * _DISPATCH_SIZEOF_PTR) | ||
(_DISPATCH_CONTINUATION_PTRS * __SIZEOF_POINTER__) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
__SIZEOF_POINTER__
is not standard afaict which is why dispatch does it this way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, it's not standard. Isn't clang a requisite though? The other ones seem fine though, so, let me drop this part, and we can address it separately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, is __LP64__
standard? I don't believe that MSVC defines that.
Dropped the |
@MadCoder anything else for this part of the change? |
src/allocator_internal.h
Outdated
#else | ||
#define SIZEOF_HEADER 8 | ||
#endif | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather keep the SIZEOF_HEADER to a define to the right sizeof()
src/allocator_internal.h
Outdated
|
||
#define MAPS_TO_FPMAPS_PADDING (PADDING_TO_CONTINUATION_SIZE(SIZEOF_MAPS)) | ||
|
||
#define BYTES_LEFT_IN_FIRST_PAGE (BYTES_PER_PAGE - \ | ||
(SIZEOF_HEADER + HEADER_TO_SUPERMAPS_PADDING + SIZEOF_SUPERMAPS + \ | ||
(sizeof(struct dispatch_magazine_header_s) + HEADER_TO_SUPERMAPS_PADDING + SIZEOF_SUPERMAPS + \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and keep SIZEOF_HEADER here which has the side effect of keeping it to 80 columns
@@ -97,25 +97,20 @@ | |||
// Use the largest type your platform is comfortable doing atomic ops with. | |||
// TODO: rdar://11477843 | |||
typedef unsigned long bitmap_t; | |||
#if defined(__LP64__) | |||
#define BYTES_PER_BITMAP 8 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as the other guy, makes this sizeof(bitmap_t)
src/allocator_internal.h
Outdated
|
||
#define BITMAP_C(v) ((bitmap_t)(v)) | ||
#define BITMAP_ALL_ONES (~BITMAP_C(0)) | ||
|
||
// Stop configuring. | ||
|
||
#define CONTINUATIONS_PER_BITMAP (BYTES_PER_BITMAP * 8) | ||
#define CONTINUATIONS_PER_BITMAP (sizeof(bitmap_t) * 8) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you're feeling pedantic, that 8 should be CHAR_BIT
src/allocator_internal.h
Outdated
@@ -138,8 +133,8 @@ typedef unsigned long bitmap_t; | |||
// this will round up such that first_bitmap_in_same_page() can mask the address | |||
// of a bitmap_t in the maps to obtain the first bitmap for that same page | |||
#define ROUND_UP_TO_BITMAP_ALIGNMENT(x) \ | |||
(((x) + ((BITMAPS_PER_PAGE * BYTES_PER_BITMAP) - 1u)) & \ | |||
~((BITMAPS_PER_PAGE * BYTES_PER_BITMAP) - 1u)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert
src/allocator_internal.h
Outdated
@@ -148,7 +143,7 @@ typedef unsigned long bitmap_t; | |||
#define PADDING_TO_CONTINUATION_SIZE(x) (ROUND_UP_TO_CONTINUATION_SIZE(x) - (x)) | |||
|
|||
#define SIZEOF_SUPERMAPS (BYTES_PER_SUPERMAP * SUPERMAPS_PER_MAGAZINE) | |||
#define SIZEOF_MAPS (BYTES_PER_BITMAP * BITMAPS_PER_SUPERMAP * \ | |||
#define SIZEOF_MAPS (sizeof(bitmap_t) * BITMAPS_PER_SUPERMAP * \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert
src/allocator_internal.h
Outdated
@@ -171,7 +166,7 @@ typedef unsigned long bitmap_t; | |||
#define REMAINDER_IN_FIRST_PAGE (BYTES_LEFT_IN_FIRST_PAGE - \ | |||
(FULL_BITMAPS_IN_FIRST_PAGE * CONSUMED_BYTES_PER_BITMAP) - \ | |||
(FULL_BITMAPS_IN_FIRST_PAGE ? 0 : \ | |||
ROUND_UP_TO_CONTINUATION_SIZE(BYTES_PER_BITMAP))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert
src/allocator_internal.h
Outdated
@@ -181,7 +176,7 @@ typedef unsigned long bitmap_t; | |||
(REMAINDERED_CONTINUATIONS_IN_FIRST_PAGE == 0 ? 0 : 1)) | |||
|
|||
#define FPMAPS_TO_FPCONTS_PADDING (PADDING_TO_CONTINUATION_SIZE(\ | |||
BYTES_PER_BITMAP * BITMAPS_IN_FIRST_PAGE)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert
src/allocator_internal.h
Outdated
@@ -162,12 +156,12 @@ typedef unsigned long bitmap_t; | |||
// we want to align the maps to a continuation size, but we must also have proper padding | |||
// so that we can perform first_bitmap_in_same_page() | |||
#define SUPERMAPS_TO_MAPS_PADDING (PADDING_TO_BITMAP_ALIGNMENT_AND_CONTINUATION_SIZE( \ | |||
SIZEOF_SUPERMAPS + HEADER_TO_SUPERMAPS_PADDING + SIZEOF_HEADER)) | |||
SIZEOF_SUPERMAPS + HEADER_TO_SUPERMAPS_PADDING + sizeof(struct dispatch_magazine_header_s))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
revert
Rather than trying to compute the size of the magazine header manually, use the compiler's builtin `sizeof` operator.
Rather than hardcoding the sizeof(bitmap_t) based on `__LP64__` use the compiler builtin `sizeof` to compute the size.
Updated and also changed the |
@swift-ci please test |
@swift-ci please test |
@MadCoder good to go on this? |
I'm going to revert this, it breaks the build on Darwin with:
|
Change a few places to use
sizeof
rather than hard coding the size of structures and types based on pointer size.